package com.tang.algorithm.ordinary;

/**
 * @author tlm
 * @Description
 * @date 2020/6/10 6:39 下午
 */
public class LeetCode9 {
    public static void main(String[] args) {
        System.out.println(isPalindrome(-121));
    }

    /**
     * 解法1 字符串
     */
    public static boolean isPalindrome(int x) {
        String s = String.valueOf(x);
        int size = s.length();
        int left = 0,right = size-1;
        while (left<right){
            if(s.charAt(left)!=s.charAt(right)) return false;
            left++;
            right--;
        }
        return true;
    }

    /**
     * 解法2 数字
     */
    public static boolean isPalindrome2(int x) {
        if(x < 0)
            return false;
        int cur = 0;
        int num = x;
        while(num != 0) {
            cur = cur * 10 + num % 10;
            num /= 10;
        }
        return cur == x;
    }
}
